﻿// JavaScript Document
var oldUserTypeID = -1;
var typeIDString = "";

//判断是否为中文
function isChinese( str )
{
	var lst = /[^\u4E00-\u9FA5]/; 
	return !lst.test(str);      
}
//返回字符串的长度
function GetStringLength( str )
{
	var strLength=0;
	for ( i = 0; i < str.length; i ++ )
	{
		if ( isChinese( str.charAt( i ) ) == true )
		{
			strLength = strLength + 2;
		}
		else
		{
			strLength = strLength + 1;
		}
	}
	return strLength;
}
//去掉字符串空格
String.prototype.Trim = function() 
{ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

//检查真实姓名是否符合规定
function CheckRealName()
{
	var newRealName = document.getElementById("txtRealname").value;
	if ( document.getElementById("txtRealname").value.Trim() == "" )
	{
			document.getElementById("realNameErr").innerHTML = "<span class=\"error\">姓名不能为空！</span>";
			return false;
	}
	if(newRealName.length<2||newRealName.length>8)
		{
				document.getElementById("realNameErr").innerHTML = "<span class=\"error\">真实姓名为2-8个中文！</span>";
				return false;

		}
		for (var i=0;i<newRealName.length;i++)
		{
			var rx = /^[\u4e00-\u9fa5]/;
			if (!rx.test(newRealName.substr(i,1)))
			{
				document.getElementById("realNameErr").innerHTML = "<span class=\"error\">真实姓名为2-8个中文！</span>";
				return false;
			}
		}
	
	document.getElementById("realNameErr").innerHTML = " 正确！";
	return true;
}

//检查邮箱是否符合规定
function CheckIdcard()
{
	var idcard = document.getElementById("txtIdcard").value.toUpperCase();
	////////////////
	var JYM,M;
	var Y,S;
	
	var area = "11,12,13,14,15,21,22,23,31,32,33,34,35,36,37,41,42,43,44,45,46,50,51,52,53,54,61,62,63,64,65,71,81,82,91";
	var a,c;
	if ( idcard== "" )
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">身份证号不能为空！</span>";
	
		return false;
	}

	var filter=/(^\d{15}$)|(^\d{18}$)|(^\d{17}X$)/;
	if( !filter.test( idcard ))
	{ 
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">请填写正确身份证号!</span>";
		return false; 
			
	}
	if (area.indexOf(idcard.substr(0,2))<0)
	{	
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">请填写正确身份证号!</span>";
		return false;//判断身份证号前两位行政区划代码
	}	
	S = (parseInt(idcard.substr(0,1)) + parseInt(idcard.substr(10,1))) * 7 
		+ (parseInt(idcard.substr(1,1)) + parseInt(idcard.substr(11,1))) * 9 
		+ (parseInt(idcard.substr(2,1)) + parseInt(idcard.substr(12,1))) * 10 
		+ (parseInt(idcard.substr(3,1)) + parseInt(idcard.substr(13,1))) * 5 
		+ (parseInt(idcard.substr(4,1)) + parseInt(idcard.substr(14,1))) * 8 
		+ (parseInt(idcard.substr(5,1)) + parseInt(idcard.substr(15,1))) * 4 
		+ (parseInt(idcard.substr(6,1)) + parseInt(idcard.substr(16,1))) * 2 
		+ parseInt(idcard.substr(7,1)) * 1  
		+ parseInt(idcard.substr(8,1)) * 6 
		+ parseInt(idcard.substr(9,1)) * 3 ; 
	Y = S % 11; 
	JYM = "10X98765432"; 					
	M = JYM.substr(Y,1);
	
	if(idcard.length==15)
	{
		a = idcard.substr(0,6)+"19"+idcard.substr(6,9);////15位号码在6位后加“19”
		idcard=a+M;			
	}
	var year=/^(19[0-9]{2}(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|(19(0[48]|[2468][048]|[13579][26])0229)$/;
	if(!year.test(idcard.substr(6,8)))
	{			
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">请填写正确身份证号!</span>";
		return false;////判断7~12位的年月日（分闰年和平年）
	}
	if( M!=idcard.substr(17,1))
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">请填写正确身份证号!</span>";
		return false;	////对18位身份证最后一位校验码的检查				
	}
					
	var sMsg=fristpay.CheckIdCard(idcard,document.getElementById("hidUserID").value);
	if(null != sMsg.error)
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">身份证号检查出错，请重试！</span>";
		return false;
	}
	if(sMsg.value=="-1")
	{
		document.getElementById("idcardErr").innerHTML = "<span class=\"error\">身份证号已经有人使用</span>";
							
		return false;	    
	}	
	document.getElementById("idcardErr").innerHTML = "<span class=\"error\">输入的身份证号可以正常使用！</span>";
			
	return true;
	
}
//检查支付账号是否符合规定
function CheckAccount()
{
	var newAccount = document.getElementById("txtAccount").value;
	if ( newAccount.Trim() == "" )
	{
		document.getElementById("accountErr").innerHTML = "<span class=\"error\">支付账号不能为空！</span>";
		return false;
	}
	return true;
}


//判断空间名称是否为空
function CheckSpaceName(bool)
{
	if ( document.getElementById("txtSpaceName").value.Trim() == "" )
	{
		document.getElementById("spaceNameErr").innerHTML = "<span class=\"error\">空间名称不能为空！</span>";
		return false;
	}
	if (bool)
	{
		document.getElementById("spaceNameErr").innerHTML = "输入的空间名称正确！";
		return true;
	}
	else
	{
		return true; 
	}
}
function checkInput()
{
	//判断昵称
	if ( !CheckRealName() )
	{
		document.getElementById("txtRealname").focus();
		document.getElementById("txtRealname").select();
		return false;
	}
	//检查邮箱是否符合规定
	else if ( !CheckIdcard() )
	{
		document.getElementById("txtIdcard").focus();
		document.getElementById("txtIdcard").select();
		return false;
	}else if(!CheckAccount()){
		document.getElementById("txtAccount").focus();
		document.getElementById("txtAccount").select();
		return false;
	}
	/*else if ( !CheckSpaceName(false) )
	{
		document.getElementById("txtSpaceName").focus();
		document.getElementById("txtSpaceName").select();
		return false;
	}*/
	return true;
}
//判断修改资料提交时，是否满足条件
function ModifyInfo()
{
	
	if ( checkInput()==true )
	{
		var realname = document.getElementById("txtRealname").value;
		var idcard = document.getElementById("txtIdcard").value;
		var bankname=document.getElementById("selBankname").value;
		var account= document.getElementById("txtAccount").value;
		var userid=document.getElementById("hidUserID").value;
		var iRet=fristpay.GetMoney();
		if(null!=iRet.error){
			alert(iRet.error);
		}else{
			if(iRet.value==0)
			{
				Pui.manage.MsgDiv(1,"您的玉米数量未达到最低支付标准","您的玉米数量未达到最低支付标准，不能提交申请");
				return;
			}
			if(iRet.value==-1)
			{
				Pui.manage.MsgDiv(1,"该账号不存在","该账号不存在");
				return;
			}
			if(iRet.value==-2)
			{
				Pui.manage.MsgDiv(1,"确认支付异常","确认支付异常，请稍后重试");
				return;
			}
		}
		var res = fristpay.ModifyPayInfo( userid, realname, idcard, bankname,account );
		if ( null != res.error )
		{
			alert ( res.error ) ;
		}
		else
		{
			if ( res.value == -1 )
			{
				document.getElementById("realnameErr").innerHTML = "<span class=\"error\">会员不存在！</span>";
				return;
			}
			else if ( res.value == -2 )
			{
				document.getElementById("realnameErr").innerHTML = "<span class=\"error\">输入的身份证号已经有用户使用，请重新输入！</span>";
				return;
			}
			else if ( res.value == -4 )
			{
				Pui.manage.MsgDiv(1,"确认支付失败！","确认支付失败，请稍后再试！");
				return;
			}
			else
			{
				Pui.manage.MsgDiv(1,"确认支付成功！","确认支付成功！");
				window.location.href="useradincome.aspx";
			}	
		}
	}
}



